<template>
    <view class="snowy-form">
        <uni-forms ref="formRef" :model="formData" label-position="top" :rules="rules" validate-trigger="blur" labelWidth="auto">
            <uni-forms-item label="会议室门牌号" name="name" :required="true" :rules="[{ required: true, errorMessage: '请输入会议室门牌号' }]">
            	<uni-easyinput v-model="formData.name" placeholder="请输入会议室门牌号"></uni-easyinput>
            </uni-forms-item>
            <uni-forms-item label="会议室状态" name="state" :required="true" :rules="[{ required: true, errorMessage: '请输入会议室状态' }]">
                <snowy-sel-picker :map="{key: 'value', label: 'text'}" v-model="formData.state" @getOptData="getStateOptions"  placeholder="请选择会议室状态"></snowy-sel-picker>
            </uni-forms-item>
            <uni-forms-item label="会议室类型" name="type" :required="true" :rules="[{ required: true, errorMessage: '请输入会议室类型' }]">
                <snowy-sel-picker :map="{key: 'value', label: 'text'}" v-model="formData.type" @getOptData="getTypeOptions"  placeholder="请选择会议室类型"></snowy-sel-picker>
            </uni-forms-item>
            <uni-forms-item label="负责人" name="fonPer" :required="true" :rules="[{ required: true, errorMessage: '请输入负责人' }]">
            	<uni-easyinput v-model="formData.fonPer" placeholder="请输入负责人"></uni-easyinput>
            </uni-forms-item>
        </uni-forms>
        <tui-button margin="50rpx 0" :preventClick="true" :shadow="true" @click="submit">提交</tui-button>
    </view>
</template>

<script setup name="meetingInfoForm">
    import { onLoad } from "@dcloudio/uni-app"
    import meetingInfoApi from '@/api/biz/meeting-info-api'
    import { reactive, ref, getCurrentInstance } from "vue"
    import CallbackState from "@/enum/callback-state"

    const { proxy } = getCurrentInstance()
    const formRef = ref()
    const formData = ref({})
    // 常用正则规则大全：https://any86.github.io/any-rule/
    // 去pages/biz/user/form.vue中寻找示例
    const rules = reactive({
    })
	const getStateOptions = (param, callback) => callback({ state: CallbackState.SUCCESS, data: uni.$snowy.tool.dictList('MEETINGROOM_STATUS') })
	const getTypeOptions = (param, callback) => callback({ state: CallbackState.SUCCESS, data: uni.$snowy.tool.dictList('MEETINGROOM_TYPE') })
    onLoad((option) => {
        if(!option.id){
            return
        }
        meetingInfoApi.meetingInfoDetail({
            id: option.id
        }).then(data => {
            formData.value = data
        })
    })
    const submit = () => {
        formRef.value.validate().then(res => {
            meetingInfoApi.meetingInfoSubmitForm(formData.value, !formData.value.id).then(data => {
                uni.$emit('formBack', {
                    data: data
                })
                uni.navigateBack({
                    delta: 1
                })
            })
        })
    }
</script>
<style lang="scss" scoped>
</style>
